package shops

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/shops"
    shopsReq "github.com/flipped-aurora/gin-vue-admin/server/model/shops/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type LsShopApi struct {}



// CreateLsShop 创建lsShop表
// @Tags LsShop
// @Summary 创建lsShop表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body shops.LsShop true "创建lsShop表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /lsShop/createLsShop [post]
func (lsShopApi *LsShopApi) CreateLsShop(c *gin.Context) {
	var lsShop shops.LsShop
	err := c.ShouldBindJSON(&lsShop)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsShop.CreatedBy = utils.GetUserID(c)
	err = lsShopService.CreateLsShop(&lsShop)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteLsShop 删除lsShop表
// @Tags LsShop
// @Summary 删除lsShop表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body shops.LsShop true "删除lsShop表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /lsShop/deleteLsShop [delete]
func (lsShopApi *LsShopApi) DeleteLsShop(c *gin.Context) {
	ID := c.Query("ID")
    userID := utils.GetUserID(c)
	err := lsShopService.DeleteLsShop(ID,userID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteLsShopByIds 批量删除lsShop表
// @Tags LsShop
// @Summary 批量删除lsShop表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /lsShop/deleteLsShopByIds [delete]
func (lsShopApi *LsShopApi) DeleteLsShopByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
    userID := utils.GetUserID(c)
	err := lsShopService.DeleteLsShopByIds(IDs,userID)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateLsShop 更新lsShop表
// @Tags LsShop
// @Summary 更新lsShop表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body shops.LsShop true "更新lsShop表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /lsShop/updateLsShop [put]
func (lsShopApi *LsShopApi) UpdateLsShop(c *gin.Context) {
	var lsShop shops.LsShop
	err := c.ShouldBindJSON(&lsShop)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsShop.UpdatedBy = utils.GetUserID(c)
	err = lsShopService.UpdateLsShop(lsShop)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindLsShop 用id查询lsShop表
// @Tags LsShop
// @Summary 用id查询lsShop表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询lsShop表"
// @Success 200 {object} response.Response{data=shops.LsShop,msg=string} "查询成功"
// @Router /lsShop/findLsShop [get]
func (lsShopApi *LsShopApi) FindLsShop(c *gin.Context) {
	ID := c.Query("ID")
	relsShop, err := lsShopService.GetLsShop(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(relsShop, c)
}
// GetLsShopList 分页获取lsShop表列表
// @Tags LsShop
// @Summary 分页获取lsShop表列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query shopsReq.LsShopSearch true "分页获取lsShop表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /lsShop/getLsShopList [get]
func (lsShopApi *LsShopApi) GetLsShopList(c *gin.Context) {
	var pageInfo shopsReq.LsShopSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := lsShopService.GetLsShopInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetLsShopPublic 不需要鉴权的lsShop表接口
// @Tags LsShop
// @Summary 不需要鉴权的lsShop表接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /lsShop/getLsShopPublic [get]
func (lsShopApi *LsShopApi) GetLsShopPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    lsShopService.GetLsShopPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的lsShop表接口信息",
    }, "获取成功", c)
}
